<div class="layui-body-header">
	<h2>评论管理</h2>
</div>	

<div class="layui-card-body">
	<div class="layui-fluid">
		<div class="layui-card">
          <div class="layui-card-header">
            <!-- <span>所有会员列表</span> -->
            <button type="button" class="layui-btn layui-btn-sm layui-btn-danger batchDel">
              <i class="layui-icon">&#xe640;</i>
              <span>批量删除</span>
            </button>
            <a href="javascript:;" class="layui-btn layui-btn-sm layui-btn-primary" id="search_hash">
              <i class="layui-icon">&#xe615;</i>
            </a>
          </div>
          <div class="layui-card-body">
            <table id="demo_hash" lay-filter="test"></table>
            <script type="text/html" id="barDemo_hash">
              <a href="#/layui/comDetail" class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
              <!-- <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> -->
              <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
            </script>
          </div>
      </div>    
	  </div>
	</div>
      
      

<script type="text/html" id="search_tpl_hash">
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <label class="layui-form-label">评论人ID</label>
      <div class="layui-input-block">
        <input type="text" name="talk" id="talk" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">被评论人ID</label>
      <div class="layui-input-block">
        <input type="text" name="talked" id="talked" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">操作日期</label>
      <div class="layui-inline"> 
		  <input type="text" name="handleDate" id="handleDate" class="layui-input" id="test1">
		</div>
      
    </div>
    
    
    <div class="layui-form-item">
      <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo_hash"><i class="layui-icon">&#xe615;</i> 搜索</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
      </div>
    </div>
  </form>
</script>

<script>
	
	var batchDel = document.querySelector(".batchDel");
	let checkedArr = [];
	let objArr = [];	
	
	
  layui.use(['jquery', 'mockjs', 'table', 'sidebar', 'form' , 'laydate'], function () {
    var $ = layui.jquery,
      layer = layui.layer,
      table = layui.table,
      sidebar = layui.sidebar,
      laydate = layui.laydate,
      form = layui.form;
    // 注入mock
    layui.mockjs.inject({
      'POST /demo/table/user': {
        code: 0,
        msg: "xxx",
        count: 1000,
        'data|20': [{
          'id|+1': 1,
          username: '@name',
          sex: '@boolean',
          city: '@city',
          sign: '@csentence',
          experience: '@integer',
          score: '@integer',
          classify: '@word',
          wealth: '@integer',
          auth: '@boolean'
        }]
      }
    });
    //第一个实例
    table.render({
      method: 'post',
      // size: 'sm',
      limit: 10, 
      limits: [10,20,30],
      elem: '#demo_hash',
      id:'test',
      height: 'full-235',
      url: 'https://xnsmb.xnsoft.net.cn/api/Filtrate_Xn_Comment', //数据接口
      parseData: function(res){
      	return {
      		'code':0,
      		'count':res.TotalCount,
      		"data":res._Data
      	};
      },
      page: true, //开启分页
      contentType: 'application/json',
      where: {
			  "MemLoginId": "",
			  "ToMemLoginId": "",
			  "StartTime": "",
			  "EndTime": "",
      },
      request: {
			    pageName: 'CurrentPage' //页码的参数名称，默认：page
			    ,limitName: 'PageSize' //每页数据量的参数名，默认：limit
			  },
      cols: [
        [ //表头
          {
//          field: 'id',
//          title: 'ID',
			type: 'checkbox',
//          width: 70,
            sort: true,
            align: 'center',
            fixed: 'left'
          }, {
            field: 'ToMemberName',
            title: '被点评用户',
            align: 'center',
//          width: 150
          }, {
            field: 'MemerName',
            title: '评论用户',
            align: 'center',
//          width: 150
          }, {
            field: 'Content',
            align: 'center',
            title: '评论内容',
//          width: 150
          }, {
            field: 'LikeCount',
            title: '点赞人数',
            align: 'center',
//          width: 150
          }, {
            field: 'CreateTime',
            title: '评论时间',
            align: 'center',
//          width: 150,
            sort: true
          }, {
            fixed: 'right',
//          width: 180,
            align: 'center',
            toolbar: '#barDemo_hash'
          }
        ]
      ]
    });

    $('#search_hash').on('click', function () {
      var that = this;
      // console.log($('#search_tpl_hash').html());
      sidebar.render({
        elem: that,
        content: $('#search_tpl_hash').html(),
        title: '搜索',
        shade: true,
        // shadeClose:false,
        // direction: 'left'
        // dynamicRender: false,
        // url: 'views/member/all/search.html',
        width: '500px', //可以设置百分比和px
        done: function () {
        	let timer = [];
          console.log('ccc');
          form.render();
			
			
		  laydate.render({
		    elem: '#test1',
		    type: 'datetime',
		    range: true
		  });
			
          //监听提交
          form.on('submit(formDemo_hash)', function (data) {
            // layer.msg(JSON.stringify(data.field));
            table.reload('test', {
              where: {
	              "MemLoginId": $("#talk").val(),
				  "ToMemLoginId": $("#talked").val(),
				  "StartTime": $("#handleDate").val().split(" - ")[0],
				  "EndTime": $("#handleDate").val().split(" - ")[1]
              }
            });
            return false;
          });
        }
      });
    });
    
//  table.on('checkbox(test)', function(obj){
////		  console.log("obj.checked",obj.checked); //当前是否选中状态
////		  console.log("obj.data",obj.data); //选中行的相关数据
////		  console.log("obj.type",obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
//			console.log(obj.data)
//			if(obj.type=="one"){
//				if(obj.checked){
//					objArr.push(obj)
//					checkedArr.push(obj.data.Guid)
//					console.log(objArr)
//				}else if(!obj.checked){
//					objArr.splice(objArr.indexOf(obj.data),1)
//					checkedArr.splice(checkedArr.indexOf(obj.data.Guid),1)
//					console.log(objArr)
//				}
//			}
//		
//		});

table.on('checkbox(test)', function(obj){
			var checkStatus = table.checkStatus('test');
			let temp = [];
			let tempObj = [];
			checkStatus.data.forEach((el,index)=>{
				temp.push(el.Guid);
			})
			checkedArr = temp;
			console.log(temp)
		});
    
    
    table.on('tool(test)',function(obj){
    	toolHandel("#/layui/comDetail?id=","Admin_Xn_Comment/",obj);
    })
    
    
    
//  批量删除
//  batchDel.addEventListener("click",function(){
//  	batDel("Admin_Xn_Comment/",checkedArr,objArr)
//  	
//  })
    
    batchDel.addEventListener("click",function(){
    	if(checkedArr.length!=0){
    		layer.confirm('确认删除？', function(index){
					layer.close(index);	
					console.log("checkedArr",checkedArr)
					DBHelper.Delete("Admin_Xn_Comment",checkedArr,function(data){
				      	console.log(data)
				      },function(data){
				      	table.reload('test', {
								});
				      	console.log(data)
				      })
					
		    });
    	}else if(checkedArr.length==0){
			layer.alert("请选择至少一个选项")
		}
			
			
    })
    
  });
  
  
  
  
  
</script>


<style scoped>
	.qxMaBtn{
		margin-bottom: 20px;
	}
		.qxMaInfo-table{
			font-size: 12px;
		}
		
		.qxMaInfo-table tr>th{
			text-align: center;
			font-size: 12px;
		}
		.qxMaInfo-table tr>td{
			text-align: center;
			font-size: 12px;
		}
      	.block{
      		display: block;
      	}
      	.qxMaTop-btn{
      		width: 100%;
      		text-align: center;
      	}
      	.qxMaInfo{
      		margin-top: 20px;
      		margin-bottom: 30px;
      	}
      	.qxMaTop-btn button{
      		display: inline-block;
      		width: 200px;
      		border-radius: 5px;
      	}
      	.title{
      		margin-left: 30px;
      		margin-top: 30px;
      	}
      	.save-warp{
      		width: 100%;
      		text-align: center;
      		margin-top: 20px;
      	}
      	.save-warp button{
      		display: inline-block;
      		width: 160px;
      	}
      	.qxMa-top{
      		display: flex;
      		justify-content: space-between;
      	}
      	.qxMa-table{
      		background-color: rgba(0,0,0,0);
      	}
      	.date{
      		width: 100px;
      	}
      	
      </style>



